<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>注册</title>
	<link rel="stylesheet" type="text/css" href="css/register-login.css">
</head>
<body>
<div id="box"></div>
<div class="cent-box register-box">
	<div class="cent-box-header">
		<h2 class="sub-title">富宏堂中医馆</h2>
	</div>

	<div class="cont-main clearfix">
		<div class="index-tab">
			<div class="index-slide-nav">
				<a href="login.html">登录</a>
				<a href="register.html" class="active">注册</a>
				<div class="slide-bar slide-bar1"></div>				
			</div>
		</div>

		<div class="login form">
			<div class="group">
				<div class="group-ipt">
                    <input type="text" name="username" id="username" class="ipt" placeholder="用户名" required>
                </div>
                <div class="group-ipt user">
                    <input type="password" name="password" id="password" class="ipt" placeholder="密码" required>
                </div>
                <div class="group-ipt user">
                    <input type="number" name="age" id="age" class="ipt" placeholder="年龄" required>
                </div>
                <div class="group-ipt user">
                    <input type="text" name="idcard" id="idcard" class="ipt" placeholder="身份证" required>
                </div>
                <div class="group-ipt user">
                    <input type="text" name="telphone" id="telphone" class="ipt" placeholder="电话" required>
                </div>
                <div style="font-size: 14px;margin-left: 10px;height: 35px;padding-top: 13px" class="user">
	                <span>性别</span>&nbsp;&nbsp;
			                    男<input type="radio" name="sex" id="sex" class="ipt" value="男" checked="checked">
			      &nbsp;&nbsp;女<input type="radio" name="sex" id="sex" class="ipt" value="女">
		        </div>
			</div>
		</div>

		<div class="button">
			<button type="submit" class="login-btn register-btn" id="button" style="background-color: #d9534f;">注册</button>
		</div>
	</div>
</div>

<script src='js/jquery-1.8.3.min.js' type="text/javascript"></script>
<script>

	$(".login-btn").click(function(){
		var username=$("#username").val();
		var age = $("#age").val();
		var password = $("#password").val();
		var idcard = $("#idcard").val();
		var telphone = $("#telphone").val();
		var sex=$("input[name='sex'][checked]").val(); 
		if(username==''||age==''||password==''||idcard==''||telphone==''){
			alert('请填写完整信息！');
			return;
		}
		var data={'username':username,'password':password,'telphone':telphone,
		         'age':age,'idcard':idcard,"sex":sex};
		
		//重名校验
		$.ajax({
			type:"post",
			url:"/user/checkName",
			data:{'username':username},
			async:false,
			success:function(res){
				if(res.resultCode!=200){
					alert("用户名重复!");
					return;
				}else{
					//提交表单
			        $.ajax({
			            type:"post",
			            data:JSON.stringify(data),
			            contentType: "application/json; charset=utf-8",
			            url:"/user/insert",
			            async:true,
			            success:function(res){
			                if(res.resultCode==200){
			                    alert('注册成功');
			                    window.location.href='login.html';
			                }
			            }
			        });
				}
			}
		})
	})
	
</script>
</body>
</html>